define(['jquery', 'bootstrap', 'utilback', 'table', 'form'], function ($, undefined, Utilback, Table, Form) {

    var Controller = {
    	config: {
    		get_url: '/store/read/detail',
    	},
        init: function () {
            // 初始化表格参数配置
            Table.api.init({
            	singleSelect: true,
                extend: {
                    index_url: '/store/read/list',
                    add_url: 'storeEdit.html',
                    edit_url: 'storeEdit.html',
                    del_url: '/store',
                    multi_url: '/store',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                columns: [
                    [
                        {field: 'state', checkbox: true, },
                        {field: 'id', title: 'ID'},
                        {field: 'storeIcon', title: __('店铺图标'), formatter: function (v, row, index) {
                        	return v ? '<img class="view" title="' + row.userName + '" height="30px" src="'+v+'">' : '';
                        }},
                        {field: 'storeName', title: __('店铺名称')},
                        {field: 'storePhone', title: __('电话')},
                        {field: 'storeAddress', title: '地址'},
                        {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
                             return Table.api.formatter.operate.call(this, value, row, index, table);
                        }}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        edit: function () {
            Form.api.bindevent($("form[role=form]"));
            Util.api.initSelectOption({
        		target : '[name="sellerId"]',
        		url: '/seller/read/list',
        		code: 'id',
        		codeText: 'sellerName',
        		param : {},
        		init: function() {
        			var id = Util.api.query('id');
     	        	if(id) {
     	        		Form.api.fill($('form'), Controller.config.get_url, id, function(data) {
     	    				if(data.storeIcon) {
     	    					$('#prev1').append('<img src="' + data.storeIcon + '" height="30px">');
     	    				}
     	    				if(data.audioCommentary) {
     	    					$('#prev2').append('<audio src="'+data.audioCommentary
     	    					+'" controls="controls" preload="auto">您浏览器不支持音频播放器</audio>');
     	    				}
     	    				if(data.audioCommentary) {
     	    					$('#prev3').append('<video src="'+data.audioCommentary
     	    					+'" controls="controls" height="50px" width="100px">您浏览器不支持视频播放器</video>');
     	    				}
     	    				$('.summernote').summernote('code', data.storeDesc);
            				$('[name="sellerId"]').selectpicker('val',data.sellerId);
     	        		});
     	        	}
        		}
        	});
            $('#lonLat').on('click', function() {
            	Util.api.open('/main/html/map.html', '高德地图坐标拾取');
            });
        }
    };
    return Controller;
});